import 'package:flutter/material.dart';
import 'package:flutter_scan_tool/models/tool.dart';

class ToolListView extends StatelessWidget {
  const ToolListView(
      {Key? key,
        this.callback,
        this.toolListData,
        this.animationController,
        this.animation})
      : super(key: key);

  final VoidCallback? callback;
  final AnimationController? animationController;
  final Animation<double>? animation;
  final ToolData? toolListData;
  final String imageUrl =
      "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500";

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: animationController!,
      builder: (BuildContext context, Widget? child) {
        return FadeTransition(
          opacity: animation!,
          child: Transform(
            transform: Matrix4.translationValues(
                0.0, 50 * (1.0 - animation!.value), 0.0),
            child: Padding(
              padding:
              const EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 8),
              child: InkWell(
                focusColor: Colors.transparent,
                highlightColor: Colors.transparent,
                hoverColor: Colors.transparent,
                splashColor: Colors.grey.withOpacity(0.8),
                onTap: callback,
                child: Container(
                  decoration: BoxDecoration(
                      borderRadius:
                      const BorderRadius.all(Radius.circular(16.0)),
                      color: Colors.red,
                      gradient: const LinearGradient(
                        colors: [
                          Color.fromARGB(255, 219, 222, 228),
                          Color.fromARGB(255, 219, 219, 228),
                        ],
                        begin: Alignment.topLeft,
                        end: Alignment.bottomRight,
                      ),
                      boxShadow: <BoxShadow>[
                        BoxShadow(
                            color: Colors.grey.withOpacity(0.3),
                            offset: const Offset(2, 2),
                            blurRadius: 16),
                      ]),
                  child: ClipRRect(
                    borderRadius: const BorderRadius.all(Radius.circular(16.0)),
                    child: Stack(
                      children: <Widget>[
                        Row(
                          children: [
                            Expanded(
                              child: Container(
                                  decoration: BoxDecoration(
                                    boxShadow: <BoxShadow>[
                                      BoxShadow(
                                          color:
                                          Colors.white10.withOpacity(0.8),
                                          offset: const Offset(0, 3),
                                          blurRadius: 6)
                                    ],
                                    shape: BoxShape.rectangle,
                                  ),
                                  child: Hero(
                                    tag: toolListData!.id,
                                    child: AspectRatio(
                                      aspectRatio: 1.18,
                                      child: Image.network(
                                        toolListData!.imgUrl.isEmpty
                                            ? imageUrl
                                            : toolListData!.imgUrl,
                                        fit: BoxFit.fill,
                                      ),
                                    ),
                                  )),
                              flex: 1,
                            ),
                            const SizedBox(
                              width: 5.0,
                            ),
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  const SizedBox(
                                    height: 8.0,
                                  ),
                                  Text(
                                    toolListData!.toolName,
                                    style: const TextStyle(
                                        fontWeight: FontWeight.w100,
                                        fontSize: 16),
                                  ),
                                  const SizedBox(
                                    height: 8.0,
                                  ),
                                  Text(
                                    toolListData!.toolSpec,
                                    style: const TextStyle(
                                        fontWeight: FontWeight.w100,
                                        fontSize: 16,
                                        fontFamily: 'times'),
                                  ),
                                  const SizedBox(
                                    height: 8.0,
                                  ),
                                  Text(
                                    toolListData!.epc,
                                    style: const TextStyle(
                                        fontWeight: FontWeight.w100,
                                        fontSize: 16,
                                        fontFamily: 'times'),
                                  ),
                                  const SizedBox(
                                    height: 8.0,
                                  ),
                                  Text(
                                    toolListData!.state > 0 ? '出库' : '在库',
                                    style: TextStyle(
                                        color: toolListData!.state == 0
                                            ? Colors.black
                                            : Colors.red,
                                        fontWeight: FontWeight.w100,
                                        fontSize: 16),
                                  ),
                                  const SizedBox(
                                    height: 8.0,
                                  ),
                                  Text(
                                    toolListData!.lockerPosition,
                                    style: const TextStyle(
                                        fontWeight: FontWeight.w100,
                                        fontSize: 16),
                                  ),
                                  const SizedBox(
                                    height: 8.0,
                                  ),
                                ],
                              ),
                              flex: 3,
                            ),
                          ],
                        ),
                        Positioned(
                          top: 8,
                          right: 8,
                          child: Material(
                            color: Colors.transparent,
                            child: InkWell(
                                borderRadius: const BorderRadius.all(
                                    Radius.circular(32.0)),
                                onTap: () {},
                                child: Icon(
                                  Icons.circle_sharp,
                                  color: toolListData!.state == 0
                                      ? const Color(0xFF54D3C2)
                                      : const Color.fromARGB(255, 230, 109, 109),
                                )),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}